#include<iostream>
#include<algorithm>
using namespace std;
int a[30000];
int main()
{
    int n;
    int i,j,k,t=1;
    long long  ans=0;
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n);
   for (i=1;i<=n-1;i++)
   {
       int flag=0;
       int sum=a[i]+a[i+1];
       for (j=i+1;j<=n;j++)
         if(sum<=a[j+1])
       {
           a[j]=sum;
           flag=1;
           break;
       }
       else a[j]=a[j+1];
       if(flag==0) a[n]=sum;
       ans+=sum;
   }
    cout<<ans<<endl;
    return 0;
}
